package org.xlp.db.sql;


import org.xlp.db.exception.EntityException;

import java.util.Arrays;

/**
 * 可含条件单表分页数据查询SQL信息类（只针对mysql数据库有效）
 * 
 * @author 徐龙平
 *         <p>
 *         2017-6-14
 *         </p>
 * @version 1.0
 */
public class MYSQLLimitSQL<T> extends AbstractPagedSQL<T> {
	/**
	 * 构造函数
	 *
	 * @param beanClass
	 * @throws EntityException
	 */
	public MYSQLLimitSQL(Class<T> beanClass) throws EntityException {
		super(beanClass);
	}

	/***
	 * 构造函数
	 * @param beanClass
	 * @param startPos
	 * @param resultCount
	 * @throws EntityException
	 */
	public MYSQLLimitSQL(Class<T> beanClass, long startPos, long resultCount)
			throws EntityException {
		super(beanClass, startPos, resultCount);
	}

	@Override
	public Object[] getParams() {
		Object[] values = super.getParams();
		if (limit != null) {
			int length = values.length;
			values = Arrays.copyOf(values, length + 2);
			values[length] = limit.getStartPos();
			values[length +1] = limit.getResultCount();
		}
		return values;
	}

	@Override
	public String getParamSql() {
		String sql = super.getParamSql();
		if (limit != null) {
			sql += " limit ?,?";
		}
		return sql;
	}
}
